package com.superbytecode.stencil.enums;

import lombok.Getter;
import org.apache.commons.lang3.ArrayUtils;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * All rights Reserved, Designed By www.super-master.com
 *
 * @ProjectName: code-stencil
 * @Package: com.superbytecode.stencil.structure.type
 * @ClassName: TemplateEnum
 * @Description: []
 * <p> </p>
 * @Author: [Lance Ting]
 * @Date: 2024/10/14 15:54
 * @Version: V1.0
 * @Copyright: 2024 www.super-master.cn Inc. All rights reserved.
 * TODO: 注意,本文件Lance Ting所作,如果转载或使用请标明具体出处!
 **/
@Getter
public enum TemplateEnum {
    // domain
    DOMAIN(10, "Domain", ".java", "Domain"),//
    // controller
    CONTROLLER(20, "Controller", ".java", "Controller"),//
    // service/impl
    SERVICE(30, "Service", ".java", "Service"),//
    IMPL(31, "ServiceImpl", ".java", "ServiceImpl"),//
    // mybatis/mybatis-plus
    MAPPER(40, "Mapper", ".java", "MybatisMapper"),//
    SETTING(41, "Mapper", ".xml", "MybatisMapper"),//
    PLUSMAPPER(50, "Mapper", ".java", "MybatisPlusMapper"),//
    PLUSSETTING(51, "Mapper", ".xml", "MybatisPlusMapper"),//
    // sql

    // vue

    ;

    public boolean isDomain(Integer code) {
        return Objects.equals(code, TemplateEnum.DOMAIN.code);
    }

    public static List<TemplateEnum> load(Integer... codes) {
        List<TemplateEnum> defaultList = Arrays.asList(values());
        if (ArrayUtils.isEmpty(codes)) {
            return defaultList;
        }
        return defaultList.stream().filter(t -> Arrays.asList(codes).contains(t.code)).collect(Collectors.toList());
    }

    final private Integer code;
    final private String module;
    final private String suffix;
    final private String file;

    TemplateEnum(Integer code, String module, String suffix, String file) {
        this.code = code;
        this.module = module;
        this.suffix = suffix;
        this.file = file;
    }
}